/**
 * @param {number[]} releaseTimes
 * @param {string} keysPressed
 * @return {character}
 */
var slowestKey = function (releaseTimes, keysPressed) {
  let n = releaseTimes.length
  let max = releaseTimes[0],str = keysPressed[0]
  for (let i = 1; i < n; i++) {
    if(releaseTimes[i] - releaseTimes[i-1] > max){
      max = releaseTimes[i] - releaseTimes[i - 1]
      str = keysPressed[i]
    } else if (releaseTimes[i] - releaseTimes[i - 1] === max){
      str = keysPressed[i] > str ? keysPressed[i] : str
    }
  }
  return str
};

var releaseTimes = [12, 23, 36, 46, 62],keysPressed = "spuda"
console.log(slowestKey(releaseTimes,keysPressed))
